Skip to content

logcoordinator: improve log#4206

Merged
ti-chi-bot[bot] merged 4 commits intomasterfrom
ldz/fix-resign-log-coordinator
Feb 24, 2026
Merged

logcoordinator: improve log#4206
ti-chi-bot[bot] merged 4 commits intomasterfrom
ldz/fix-resign-log-coordinator

Conversation

@lidezhu
Copy link
Collaborator

@lidezhu lidezhu commented Feb 13, 2026

What problem does this PR solve?

Issue Number: ref #2751

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

Summary by CodeRabbit

  • Bug Fixes

    • Resignation handling for the log coordinator softened so campaigns no longer fail on resignation timeouts or non-critical resignation errors.
  • New Features

    • Log-coordinator revision/version is now captured and included in campaign and exit logs for improved observability.
  • Tests

    • Added unit tests covering revision retrieval and resignation edge cases.
  • Chores

    • Added supporting client API surface and mocks to enable revision retrieval in tests and runtime.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Feb 13, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @lidezhu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the stability and correctness of the log coordinator's resignation process. The changes ensure that the system handles server shutdown and resignation timeouts more gracefully, preventing potential issues during critical operational phases. The modifications improve the robustness of the election mechanism by refining how resignation attempts are managed and how errors are propagated.

Highlights

  • Log Coordinator Resignation Logic: Refactored the campaignLogCoordinator function to correctly call resignLogCoordinator and adjusted its error handling to prevent premature exits when the server is stopping.
  • Improved Resignation Error Handling: Modified the resignLogCoordinator function to use defer cancel() for context management and refined the error handling for resignation timeouts, ensuring that a timeout during resignation is logged as a warning but does not prevent the process from continuing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • server/module_election.go
    • Updated the call from e.resign(ctx) to e.resignLogCoordinator() within the campaignLogCoordinator function.
    • Adjusted the error return logic in campaignLogCoordinator when the server is stopping and resignation fails, to allow the process to continue.
    • Introduced defer cancel() in resignLogCoordinator to ensure context cancellation.
    • Modified error logging and return behavior in resignLogCoordinator for context.DeadlineExceeded errors, logging them as warnings and returning nil.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b00729 and 02841db.

📒 Files selected for processing (1)
  • pkg/etcd/etcd_mock.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/etcd/etcd_mock.go

📝 Walkthrough

Walkthrough

Adds an etcd API to fetch the log coordinator's revision and updates election resignation logic to fetch and log the coordinator version and to treat resignation timeouts/failures as non-fatal (log and return nil).

Changes

Cohort / File(s) Summary
Election logic
server/module_election.go
Reworks log-coordinator resignation flow: call resignLogCoordinator() with defer cancel(), fetch and include logCoordinatorVersion in logs, treat resignation timeouts and failures as non-fatal (log and return nil), and adjust log levels/messages.
Etcd owner API & impl
pkg/etcd/etcd.go
Adds OwnerCaptureInfoClient.GetLogCoordinatorRevision(ctx, captureID) (int64, error) and implements it in CDCEtcdClientImpl to read LogCoordinatorKey, validate the capture ID, and return the key's ModRevision.
Etcd mocks
pkg/etcd/etcd_mock.go
Adds gomock methods and recorder entries for GetLogCoordinatorRevision on owner capture info and CDC etcd client mocks.
Etcd tests
pkg/etcd/etcd_test.go
Adds TestCDCEtcdClientImpl_GetLogCoordinatorRevision covering leader fetch error, not found, not owner, and success scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Campaign as "Campaign Manager"
    participant Etcd as "Etcd (OwnerCaptureInfoClient)"
    participant LogCoord as "Log Coordinator"

    Campaign->>Etcd: GetLogCoordinatorRevision(captureID)
    Etcd-->>Campaign: modRevision or error
    Campaign->>LogCoord: start campaign (include revision)
    LogCoord-->>Campaign: campaign result (success / error)
    Campaign->>LogCoord: resign (resignCtx with 5s timeout)
    alt resign timeout or failure
        LogCoord-->>Campaign: timeout/error (logged, treated as nil)
    else successful resign
        LogCoord-->>Campaign: success (logged with version)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped to check the log's old mark,
Found revisions hidden in the dark,
I softened resigns with gentle cheer,
Versions logged so exits are clear,
The burrow hums — campaigns persevere.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description follows the template structure but lacks critical details: 'What is changed and how it works?' section is empty, all questions are unanswered, release notes are not filled, and testing decisions are unclear (multiple boxes checked without details). Fill in the empty sections: explain the changes and how they work, answer the compatibility and documentation questions, specify which tests were added, and provide a proper release note or state 'None' if not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'logcoordinator: improve log' is vague and does not clearly convey the specific changes made, such as improving error handling, adding log coordinator version tracking, or adding new etcd methods. Provide a more specific title that describes the main change, e.g., 'logcoordinator: add version tracking and improve resign error handling' or similar.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ldz/fix-resign-log-coordinator

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in the log coordinator's resign logic. The changes correctly replace a generic resign call with the specific resignLogCoordinator function and address incorrect error handling and logging within it. The logic for handling resign failures during server shutdown is also improved for clarity. My review includes a suggestion to remove a redundant log message, which will make the error handling cleaner and more consistent with the existing codebase.

Comment on lines +290 to +292
log.Info("log coordinator resign failed",
zap.String("nodeID", nodeID), zap.Error(resignErr))
return errors.Trace(resignErr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This log message is redundant. The primary caller of resignLogCoordinator in campaignLogCoordinator (line 231) already logs a WARN message when this function returns an error. To avoid duplicate logs and to keep the function's responsibility focused on the resign action, it's better to remove this log.Info call and just return the error. This change would also align resignLogCoordinator with the pattern used in the resign function, which does not perform logging itself.

return errors.Trace(resignErr)

@lidezhu lidezhu changed the title logcoordinator: fix resign logcoordinator: improve log Feb 13, 2026
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/module_election.go (1)

250-259: ⚠️ Potential issue | 🟡 Minor

Original co.Run error is lost when resignLogCoordinator fails.

On line 253, if resignLogCoordinator() returns an error, that resign error is returned immediately via errors.Trace(resignErr), but the original err from co.Run(ctx) (which triggered the resign) is never logged. Consider logging the original error before returning the resign error.

Proposed fix
 		if err != nil && !errors.Is(err, context.Canceled) {
 			if !errors.ErrNotOwner.Equal(err) {
 				if resignErr := e.resignLogCoordinator(); resignErr != nil {
+					log.Warn("log coordinator resign failed after run error",
+						zap.String("nodeID", nodeID),
+						zap.Int64("logCoordinatorVersion", logCoordinatorVersion),
+						zap.Error(err))
 					return errors.Trace(resignErr)
 				}
 			}
🧹 Nitpick comments (2)
pkg/etcd/etcd.go (1)

604-620: Reusing ErrOwnerNotFound / ErrNotOwner for a log coordinator role is semantically misleading.

Lines 613 and 617 return ErrOwnerNotFound and ErrNotOwner respectively, but this method checks log coordinator ownership, not the coordinator/owner role. The caller in module_election.go (line 251) checks errors.ErrNotOwner.Equal(err) to decide whether to resign, so reusing these errors works functionally, but it conflates two distinct election roles in diagnostics and error messages.

Consider introducing ErrLogCoordinatorNotFound and ErrNotLogCoordinator for clarity, or at minimum add a comment explaining why the owner errors are intentionally reused here.

pkg/etcd/etcd_test.go (1)

280-291: Missing defer ctrl.Finish() in subtests — inconsistent with existing tests.

The existing TestCDCEtcdClientImpl_GetChangefeedInfoAndStatus (line 257) explicitly calls defer ctrl.Finish(). Each subtest here creates a gomock.Controller but omits the deferred Finish(). While gomock v1.5+ auto-registers cleanup, being consistent with the rest of the file avoids confusion.

Add `defer ctrl.Finish()` after each `gomock.NewController` call
 	t.Run("get leader failed", func(t *testing.T) {
 		ctrl := gomock.NewController(t)
+		defer ctrl.Finish()
 		client := NewMockClient(ctrl)

Apply similarly for the other three subtests.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 24, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 24, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 24, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, hongyunyan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [3AceShowHand,hongyunyan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 24, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-24 04:28:21.928195877 +0000 UTC m=+156374.442990486: ☑️ agreed by 3AceShowHand.
  • 2026-02-24 04:39:23.900826547 +0000 UTC m=+157036.415621146: ☑️ agreed by hongyunyan.

@lidezhu
Copy link
Collaborator Author

lidezhu commented Feb 24, 2026

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 24, 2026
@lidezhu
Copy link
Collaborator Author

lidezhu commented Feb 24, 2026

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 24, 2026
@ti-chi-bot ti-chi-bot bot merged commit 7e03137 into master Feb 24, 2026
26 checks passed
@ti-chi-bot ti-chi-bot bot deleted the ldz/fix-resign-log-coordinator branch February 24, 2026 06:01
lidezhu added a commit that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants